import sys

from tornado import web, ioloop
from peewee_async import Manager
import wtforms_json

from blog.urls import url_pattern
from blog.settings import settings, database


def main():
    port = 80
    # ip = '127.0.0.1'

    wtforms_json.init()

    app = web.Application(url_pattern, debug=True, **settings)
    app.listen(port)

    objects = Manager(database)
    database.set_allow_sync(False)
    app.objects = objects

    print(f'start server Success! {port}')

    ioloop.IOLoop.current().start()


if __name__ == '__main__':
    main()
